package com.devilvan.customSort;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class FlowSortBean implements WritableComparable<FlowSortBean> {
    private String msiSdn;
    private Long upPackNum;
    private Long upPayLoad;
    private Long downPackNum;
    private Long downPayLoad;

    @Override
    public int compareTo(FlowSortBean o) {
        // 二次排序
        // 先对downPackNum升序排序
        int flag = downPackNum.compareTo(o.downPackNum);
        // 值相等再对upPayLoad降序排序
        if (flag == 0) return -upPayLoad.compareTo(o.upPayLoad);
        return flag;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(msiSdn);
        out.writeLong(upPackNum);
        out.writeLong(downPackNum);
        out.writeLong(upPayLoad);
        out.writeLong(downPayLoad);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.msiSdn = in.readUTF();
        this.upPackNum = in.readLong();
        this.downPackNum = in.readLong();
        this.upPayLoad = in.readLong();
        this.downPayLoad = in.readLong();
    }

    public String getMsiSdn() {
        return msiSdn;
    }

    public void setMsiSdn(String msiSdn) {
        this.msiSdn = msiSdn;
    }

    public Long getUpPackNum() {
        return upPackNum;
    }

    public void setUpPackNum(Long upPackNum) {
        this.upPackNum = upPackNum;
    }

    public Long getUpPayLoad() {
        return upPayLoad;
    }

    public void setUpPayLoad(Long upPayLoad) {
        this.upPayLoad = upPayLoad;
    }

    public Long getDownPackNum() {
        return downPackNum;
    }

    public void setDownPackNum(Long downPackNum) {
        this.downPackNum = downPackNum;
    }

    public Long getDownPayLoad() {
        return downPayLoad;
    }

    public void setDownPayLoad(Long downPayLoad) {
        this.downPayLoad = downPayLoad;
    }

    @Override
    public String toString() {
        return "FlowSortBean{" +
                "msiSdn='" + msiSdn + '\'' +
                ", upPackNum=" + upPackNum +
                ", upPayLoad=" + upPayLoad +
                ", downPackNum=" + downPackNum +
                ", downPayLoad=" + downPayLoad +
                '}';
    }
}
